/**
 * 功能 查看当前工作空间的所有仓库的修改状态
 *
 * 由于架构：需要满足 供 本项目使用， 供其他工作空间使用
 *
 *
 *
 * cd到空间 仓库，
 * 然后git diff 文件
 * 拿到 空间 仓库 ，然后文件
 *
 *
 * */

const path = require('path');
const fs = require("fs");
const cProcess = require("child_process");
const Tools = require("../tools.js");
const git = require("./git.js");
module.exports = function (req, res) {
  const cwd = process.cwd();
  const tools = Tools(req.ctoolsOpt.devToolsDir);
  const {filePath, workspace, repertory} = req.query;
  const conf = tools.getWorkspaceConf(workspace)[0];
  const repertoryPath = path.join(cwd, conf.dto.repertoryPath, repertory);
  try {
    process.chdir(repertoryPath);
    const diff = cProcess.execSync(`git diff ${filePath}`, {encoding: "utf-8"});
    const sentData = tools.parseGitDiff(diff, repertory);
    process.chdir(cwd);
    res.send({data: sentData, code: 0});
  } catch (e) {
    process.chdir(cwd);
    res.send({data: "fail", code: 1});
  }
};
